package com.kiloai.digcust.mvp.model;

import android.content.Context;

import com.google.gson.reflect.TypeToken;
import com.kiloai.base.entity.User;
import com.kiloai.base.okgohttp.AppApis;
import com.kiloai.base.okgohttp.HttpHandler;
import com.kiloai.base.okgohttp.callback.JsonDialogCallback;
import com.kiloai.base.okgohttp.callback.RequestCallback;
import com.kiloai.base.okgohttp.entity.Data;
import com.lzy.okgo.model.Response;

import java.lang.reflect.Type;
import java.util.Map;

/**
 * Created by david on 2018/8/20.
 */

public class PersonalModel {

    /**
     * 登录
     * @param context
     * @param data
     * @param callback
     */
    public static void login(Context context, Map<String,String> data, final RequestCallback<User> callback) {

        String url = AppApis.login();
        Type type = new TypeToken<Data<User>>() {
        }.getType();
        HttpHandler.getInstance(context.getClass().getSimpleName()).postRequest(url, data,new JsonDialogCallback<User>(context, type) {
            @Override
            public void onSuccess(Response<User> response) {
                User user = response.body();
                if (user != null) {
                    callback.onSuccess(user);
                }
            }
        });
    }
}
